import axios from 'axios'
import wx from "weixin-js-sdk";
import api from '../request/api'

// 全局微信分享
const wxsdk = function () {
  return new Promise(function (res) {
    axios.post(api.Share, {
      "url": window.location.href,
    }).then((res) => {
      if (res.data.code == 1) {
        let data = res.data.data.signPackage
        wx.config({
          debug: false,
          appId: data.appId,
          timestamp: data.timestamp,
          nonceStr: data.nonceStr,
          signature: data.signature,
          jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone", "getLocation", "openLocation"],
        });
      }
    });

    wx.ready(() => {


      res(wx)
    })
  })
}


export default wxsdk

